package org.tobaccomain.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.tobaccomain.pojo.dto.PageEmployee;
import org.tobaccomain.pojo.dto.Password;
import org.tobaccomain.pojo.entity.Employee;
import org.tobaccomain.pojo.entity.Result;
import org.tobaccomain.pojo.vo.EmployeeLogin;
import org.tobaccomain.pojo.vo.PageResult;
import org.tobaccomain.service.EmployeeService;

@Slf4j
@RestController
public class EmployeeController {
    @Autowired
    private EmployeeService employeeService;
//    //添加员工信息
//    @PostMapping("/employee")
//    public Result addEmlpoyee(@RequestBody Employee employee ){
//        log.info("添加员工信息:{}",employee);
//        employeeService.addEmployee(employee);
//        return Result.success("员工添加成功");
//    }

//    //删除员工信息
//    @DeleteMapping("/employee")
//    public Result delEmployeeById(Integer id){
//        employeeService.delEmployeeById(id);
//        return  Result.success("员工删除成功");
//    }
//
//    //编辑员工信息
//    @PutMapping("/employee")
//    public Result modifyEmployee(@RequestBody Employee employee){
//        employeeService.modifyEmployee(employee);
//        return Result.success("员工编辑成功");
//    }
//
//    //员工分页查询
//    @GetMapping("/employee/page")
//    public Result getEmployeeList(PageEmployee pageEmployee){
//        log.info("员工分页查询参数:{}",pageEmployee);
//        PageResult pageResult = employeeService.getEmployeeList(pageEmployee);
//        return Result.success(pageResult);
//    }
//
//    //根据id获取员工信息
//    @GetMapping("/employee")
//    public Result getEmployeeById(Integer id){
//        Employee employee = employeeService.getEmployeeById(id);
//        return Result.success(employee);
//    }

//    //员工忘记密码
//    @PostMapping("/user/forget")
//    public Result forgetPassword(@RequestBody Employee employee){
//        Employee e = employeeService.forgetPassword(employee);
//        if(e != null){
//            return Result.success("密码重置成功");
//        }else {
//            return Result.error("用户不存在，密码重置失败");
//        }
//    }

    //员工登录
    @PostMapping("/login")
    public Result login(@RequestBody Employee employee){
        EmployeeLogin employeeLogin=employeeService.login(employee);

        if(employeeLogin != null){
            return new Result(1,"登录成功",employeeLogin);
        }else {
            return Result.error("用户名或者密码错误");
        }
    }

    //员工密码修改
    @PutMapping("/user/password")
    public Result modifyPassword(@RequestBody Password password){
        log.info("员工密码修改参数:{}",password);
        employeeService.modifyPassword(password);
        return Result.success("密更改成功,请重新登录");
    }


}
